package com.liu.activiti.controller;

import com.liu.activiti.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @ClassName Login
 * @Author ：name
 * @Date ：2022-01-25 14:02
 * @Description：
 * @Version: 1.0
 */
@Api(value = "登录登出接口")
@Controller
public class Login {

    @Autowired
    LoginService loginservice;

    @ApiOperation("登录认证")
    @RequestMapping(value = "/loginvalidate", method = RequestMethod.POST)
    public String loginvalidate(@RequestParam("username") String username, @RequestParam("password") String pwd, HttpSession httpSession) {

        if(username==null){
            return "login";
        }
        String realpwd=loginservice.getpwdbyname(username);
        if(realpwd!=null&&pwd.equals(realpwd))
        {
            httpSession.setAttribute("username", username);
            return "index";
        }else{
            return "fail";
        }


    }


    @RequestMapping(value="/login",method = RequestMethod.GET)
    public String login(){
        return "login";
    }
}
